<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>会员注册</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/lib/layui/layui.js"
            charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        #thumb-box {
            position: relative;
        }

        #thumb {
            width: 200px;
            height: 290px;
            position: absolute;
            left: 328px;
            top: -252px;
            display: none;
        }
    </style>
</head>

<body class="layui-anim layui-anim-up">
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">前台系统</a>
        <a>
          <cite>注册会员</cite></a>
      </span>
</div>
<div class="x-body" style="margin: 200px 200px">
    <form class="layui-form" id="registerForm">
        <div class="layui-form-item">
            <label for="memberName" class="layui-form-label">
                <span class="x-red">*</span>会员名
            </label>
            <div class="layui-input-inline">
                <input type="text" id="memberName" name="memberName" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="memberPhone" class="layui-form-label">
                <span class="x-red">*</span>手机号码
            </label>
            <div class="layui-input-inline">
                <input type="text" id="memberPhone" maxlength="11" name="memberPhone" required=""
                       lay-verify="phone"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="memberPassword" class="layui-form-label">
                <span class="x-red">*</span>密码
            </label>
            <div class="layui-input-inline">
                <input type="password" id="memberPassword" name="memberPassword" required="" lay-verify="password"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="memberPassword2" class="layui-form-label">
                <span class="x-red">*</span>确认密码
            </label>
            <div class="layui-input-inline">
                <input type="password" id="memberPassword2" name="memberPassword2" required="" lay-verify="password2"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
            </label>
            <button class="layui-btn" lay-filter="add" lay-submit="">注册</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </form>
    <div style="width: 243px; margin-left: 60px;">
        <button class="layui-btn layui-btn-normal layui-btn-fluid" id="rechargeBtn" STYLE="display: none" onclick="window.location='${pageContext.request.contextPath}/foreground?m=memberRechargePageFromRegister&register=1'">跳转至充值界面</button>
    </div>
</div>
<script>
    layui.use(['form', 'layer'], function () {
        $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer;


        //自定义验证规则
        form.verify({
            password: [/(.+){6,12}$/, '密码必须6到12位']
            , password2: function () {
                if ($('#memberPassword').val() != $('#memberPassword2').val()) {
                    return '两次密码不一致';
                }
            },
            phone:[/^1[0-9]{10}/,'请输入正确的电话号码']
        });

        //监听提交
        form.on('submit(add)', function (data) {
            //发异步，把数据提交给java
            $.ajax({
                type: "post",
                url: "${pageContext.request.contextPath}/foreground?m=memberRegister",
                data: data.field,
                dataType: "json",
                success: function (JsonData) {
                    layer.msg(JsonData.msg, function () {
                        if (JsonData.code === 200) {
                            $("#rechargeBtn").show();
                        }
                    });
                }
            });
            return false;
        });




        // 获取分类数据
        $.ajax({
            type: "post",
            url: "${pageContext.request.contextPath}/department?m=getAllDepartment",
            dataType: "json",
            success: function (data) {
                if (data.code === 200) {
                    $("select[name=workerDepartmentCode]").empty();
                    $(data.data).each(function () {
                        if ($("#workerDepartmentCode").val() === this.departmentCode) {
                            $("select[name=workerDepartmentCode]").append("<option value='" + this.departmentCode + "' selected>" + this.departmentName + "</option>")
                        } else {
                            $("select[name=workerDepartmentCode]").append("<option value='" + this.departmentCode + "'>" + this.departmentName + "</option>")
                        }
                    });
                    // 重新渲染
                    form.render('select');
                }
            }
        });
    });


</script>

</body>

</html>